import { http } from "@/utils/http";

export type ChargeStandardItem = {
  id: number;
  cellName?: string;
  cellId: number;
  chargeitemName?: string;
  chargeitemId: number;
  name: string;
  chargetypeName?: string;
  price: number;
  pricestr: string;
  remarks: string;
  timeset: number;
  createTime?: string;
  updateTime?: string;
  tenantId?: number;
};

export type ChargeStandardListParams = {
  page: number;
  limit: number;
  name: string;
};

export type ChargeStandardListResult = {
  code: number;
  data: {
    total: number;
    list: ChargeStandardItem[];
    pageNum: number;
    pageSize: number;
    size: number;
    startRow: number;
    endRow: number;
    pages: number;
    prePage: number;
    nextPage: number;
    isFirstPage: boolean;
    isLastPage: boolean;
    hasPreviousPage: boolean;
    hasNextPage: boolean;
    navigatePages: number;
    navigatepageNums: number[];
    navigateFirstPage: number;
    navigateLastPage: number;
  };
  message: string;
};

export type ChargeStandardAddParams = {
  name: string;
  chargeitemId: number;
  cellId: number;
  price: number;
  timeset: number;
  remarks: string;
};

export type ChargeStandardUpdateParams = {
  id: number;
  name: string;
  chargeitemId: number;
  cellId: number;
  price: number;
  timeset: number;
  remarks: string;
};

// 获取收费标准列表
export const getChargeStandardList = (params: ChargeStandardListParams) => {
  return http.request<ChargeStandardListResult>(
    "post",
    "/SpChargeStandards/listByQuery",
    {
      data: params
    }
  );
};

// 新增收费标准
export const addChargeStandard = (params: ChargeStandardAddParams) => {
  return http.request("post", "/SpChargeStandards/add", { data: params });
};

// 更新收费标准
export const updateChargeStandard = (params: ChargeStandardUpdateParams) => {
  return http.request("put", "/SpChargeStandards/update", { data: params });
};

// 根据收费类型名称查询收费标准列表
export const getChargeStandardListByChargeTypeName = (params: {
  page: number;
  limit: number;
  name: string;
}) => {
  return http.request<{
    code: number;
    data: ChargeStandardItem[];
    message: string;
  }>("post", "/SpChargeStandards/queryListBychargeTypeName", {
    data: params
  });
};
